package com.shop2cn.iapi.agentproducts.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.EditProductRebateBean;
import com.shop2cn.iapi.agentproducts.parameter.GetProductRebateListBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.shop2cn.iapi.agentproducts.service.GetProductRebateListCall;
import com.ymatou.iapi.godmch.parameter.createDepotBean;
import com.ymatou.iapi.godmch.parameter.createagentBean;
import com.ymatou.iapi.godmch.service.createagentCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.mch_depot_info;
/**
*商品分佣列表Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetProductRebateList{
	private static GetProductRebateListBean getproductrebatelistBean;
	private static GetProductRebateListCall getproductrebatelistCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商品分佣列表Test");
		
	}

	@Before
	public void caseUp() {
		getproductrebatelistBean=new GetProductRebateListBean();
		getproductrebatelistCall=new GetProductRebateListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getproductrebatelistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductRebateList_001() {
		Logger.start(true,"查询分佣列表，成功");
		try {
			
			//创建一个商户和分销小店
			Integer MchId = GodmchManageCallService.CreateGodMch();
			Integer StoreId = GodmchManageCallService.CreateStores(MchId, 20);
			//创建商品，小店会继承
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(MchId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			EditProductRebateBean initEditProductRebateBean = AddAgentProductCallService.initEditProductRebateBean(productId, StoreId, MchId, 20);
			AddAgentProductCallService.EditProductRebateBean(initEditProductRebateBean);
			
			
			getproductrebatelistBean.setUserId(StoreId);
			getproductrebatelistBean.setAgentType(-1);
			getproductrebatelistBean.setShowRebateProduct(1);
			getproductrebatelistBean.setPageIndex(1);
			getproductrebatelistBean.setPageSize(20);
			getproductrebatelistCall.setData(getproductrebatelistBean);
			getproductrebatelistCall.callService();
			Logger.verifyEquals("200", getproductrebatelistCall.getString("code"), "验证code");
			
			JsonArray productRebateDtoList = getproductrebatelistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("productRebateDtoList");
			JsonObject RebateDto = productRebateDtoList.get(0).getAsJsonObject();
			Logger.verifyEquals(RebateDto.get("productId").getAsString(), productId, "验证productId");
			Logger.verifyEquals(RebateDto.get("agentType").getAsInt(), 1, "验证agentType");
			Logger.verifyEquals(RebateDto.get("maxSalePrice").getAsDouble(),900.0, "验证maxSalePrice");
			Logger.verifyEquals(RebateDto.get("minSalePrice").getAsDouble(),900.0, "验证minSalePrice");
			Logger.verifyEquals(RebateDto.get("rebateType").getAsInt(), 1, "验证rebateType");
			Logger.verifyEquals(RebateDto.getAsJsonArray("lowerAgentList").get(0).getAsJsonObject().get("maxRebateValue").getAsDouble(), 20.0, "验证maxRebateValue");
			Logger.verifyEquals(RebateDto.getAsJsonArray("lowerAgentList").get(0).getAsJsonObject().get("minRebateValue").getAsDouble(), 20.0, "验证minRebateValue");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductRebateList_002() {
		Logger.start(true,"正确数据，成功");
		try {
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}